import 'package:flutter/material.dart';
import 'package:love_app/model/chat_sql_model.dart';

// 聊天记录共享数据
class ChatLogProvider with ChangeNotifier{
  List<ChatSqlModel> _logs = []; // 保存一百条聊天记录
  int _otherId;
  int _page = 1; // 数据库分页，要获取第几页数据
  bool _isEndPage = false; // 是否是最后一页

  List<ChatSqlModel> get logs => this._logs;
  bool _isFirst = true;

  bool _update = false; // 是否需要触发更新

  bool get update => this._update;
  set update(bool update){
    this._update = update;
  }
  
  int get otherId => this._otherId;
  set otherId(int otherId){
    this._otherId = otherId;
  }

  int get page => this._page;
  set page(int page){
    this._page = page;
  }

  bool get isFirst => this._isFirst;
  set isFirst(bool isFirst){
    this._isFirst = isFirst;
  }

  bool get isEndPage => this._isEndPage;
  set isEndPage(bool isEndPage){
    this._isEndPage = isEndPage;
  }

  void notify(){
    notifyListeners();
  }
  

  // 往list添加数据， 但是数据始终保存长度为100
  void addLog(ChatSqlModel data){
    this._logs.add(data);
  }

  void addLogInFirst(ChatSqlModel data){
    int first = 0;
    this._logs.insert(first, data);
  }
}